//
//  MBDGroupDetailModel.swift
//  MasterBoy
//
//  Created by kyson on 2023/5/7.
//

import Foundation
import SwiftyJSON

// 定义枚举
enum MBDGroupStatus {
    case under // 审核中
    case success // 审核成功
    case reject // 审核被拒绝

}


class MBDGroupContactsModel : NSObject {
    var groupOwnerName : String!
    var groupOwnerId : String!
    var smName : String!
    var smId : String!

}

class MBDGroupCommentsModel : NSObject {
    var avatarUrl : String!
    var groupCommentId : String!
    var groupId : String!
    var userId : String!
    var likeCount : String!
    var isLike : Bool!
    var realName : String!
    var comment : String!
    var createTime : String!
    var groupCommentReplyList : Array<MBDGroupCommentsReplyModel>?

    init(_ jsonData : JSON) {
        super.init()
        
        self.groupCommentId = jsonData["groupCommentId"].stringValue
        self.groupId = jsonData["groupId"].stringValue
        self.userId = jsonData["userId"].stringValue
        self.realName = jsonData["realName"].stringValue
        self.likeCount = jsonData["likeCount"].stringValue
        self.isLike = jsonData["isLike"].boolValue
        self.createTime = jsonData["createTime"].stringValue
        self.comment = jsonData["comment"].stringValue
        self.avatarUrl = jsonData["avatarUrl"].stringValue
        var tempGroupCommentReplyList = jsonData["groupCommentReplyList"].arrayValue
        
        var rstList = Array<MBDGroupCommentsReplyModel>()
        for item in tempGroupCommentReplyList {
            let modelItem = MBDGroupCommentsReplyModel(item)
            rstList.append(modelItem)
        }
        
        self.groupCommentReplyList = rstList

    }
}

class MBDUserModel : NSObject {
    var userId : String!
    var realName : String!

}

class MBDGroupCommentsReplyModel : NSObject {
    var avatarUrl : String!
    var replyId : String!
    var userId : String!
    var likeCount : String!
    var isLike : Bool!
    var replyUserId : String!
    var groupId : String!
    var realName : String!
    var replyRealName : String!
    var groupCommentId : String!
    var groupCommentReplyId : String!
    var comment : String!
    var createTime : String!
    var replyTo : MBDUserModel!

    init(_ jsonData : JSON) {
        super.init()
        
        self.replyId = jsonData["replyId"].stringValue
        self.groupId = jsonData["groupId"].stringValue
        self.likeCount = jsonData["likeCount"].stringValue
        self.isLike = jsonData["isLike"].boolValue

        self.userId = jsonData["userId"].stringValue
        self.replyUserId = jsonData["replyUserId"].stringValue
        
        self.realName = jsonData["realName"].stringValue
        self.replyRealName = jsonData["replyRealName"].stringValue
        self.createTime = jsonData["createTime"].stringValue
        self.comment = jsonData["comment"].stringValue
        self.groupCommentId = jsonData["groupCommentId"].stringValue
        self.groupCommentReplyId = jsonData["groupCommentReplyId"].stringValue
        
        self.avatarUrl = jsonData["avatarUrl"].stringValue
        self.replyTo = jsonData["replyTo"].object as? MBDUserModel
    }
    
    override init() {
        super.init()
        
    }
}


class MBDGroupDetailModel : NSObject {

    var groupId : String!
    var groupDesc : String!
    var groupLogo : String!
    var groupCodeUrl : String?
    var praisedQrUrl : String?
    
    var groupName : String!
    var groupStatus : MBDGroupStatus!
    var reason : String!
    
    var groupManager : String!
    var groupPoster : String?
    var userId : String!
    var groupPosterAvatar : String!
    var groupContats : MBDGroupContactsModel!
    var groupCommentCount : String!
    var likeCount : String!
    
    var isUnlock : String!
    
    var isLike : Bool!
    var groupLikeId : String!
    
    var createTime : String!
    
    var groupCoverURL : String!
    var groupComments : Array<MBDGroupCommentsModel>?

    override init() {
        super.init()
    }
    
    init(_ jsonData : JSON) {
        super.init()
        
        self.groupId = jsonData["groupId"].stringValue
        self.groupDesc = jsonData["groupDesc"].stringValue
        self.groupName = jsonData["groupName"].stringValue
        self.groupManager = jsonData["groupManager"].stringValue

        self.groupCodeUrl = jsonData["groupCodeUrl"].stringValue
        self.praisedQrUrl = jsonData["praisedQrUrl"].stringValue

        self.isUnlock = jsonData["isUnlock"].stringValue
        self.isLike = jsonData["isLike"].boolValue
        self.createTime = jsonData["createTime"].stringValue
        self.groupLogo = jsonData["groupLogo"].stringValue
        self.groupPoster = jsonData["groupPoster"].stringValue
        self.groupCommentCount = jsonData["groupCommentCount"].stringValue
        
        let lc = jsonData["likeCount"].stringValue
        self.likeCount =  lc.isBlank == true ? "0" : lc
        
        self.groupLikeId = jsonData["groupLikeId"].stringValue
        self.groupPosterAvatar = jsonData["avatarUrl"].stringValue
        self.userId = jsonData["userId"].stringValue
        let status = jsonData["groupStatus"].stringValue
        
        if status == "1" {
            self.groupStatus = .under
        } else if status == "3" {
            self.groupStatus = .reject
        } else {
            self.groupStatus = .success

        }
        
        self.reason = jsonData["reason"].stringValue

        
    }
}
